<template>
  <el-select
    :value="value"
    @change="changeChannel"
    placeholder="请选择频道"
    clearable
  >
    <el-option
      v-for="item in channelOptions"
      :key="item.id"
      :label="item.name"
      :value="item.id"
    >
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: 'GeekChannel',
  props: {
    value: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      channelId: null,
      channelOptions: []
    }
  },
  created () {
    this.getChannelOptions()
  },
  methods: {
    async getChannelOptions () {
      const res = await this.$http.get('/v1_0/channels')
      this.channelOptions = res.data.data.channels
    },
    changeChannel (newvalue) {
      // this.channelId = newvalue
      // v-model绑定的消息（事件）固定为input
      this.$emit('input', newvalue)
    }
  }
}
</script>

<style scoped lang='less'></style>
